//
//  VoiceLayout.m
//  SmileRead
//
//  Created by dllo on 15/8/25.
//  Copyright (c) 2015年 JIZ. All rights reserved.
//

#import "VoiceLayout.h"


@interface VoiceLayout ()

{
    CGFloat _sunOfWidth;
}

@property (nonatomic, retain) NSMutableArray *arrayOfAtt;

@end

@implementation VoiceLayout

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.arrayOfAtt = [NSMutableArray array];
        self.arrayData = [NSMutableArray array];
    }
    return self;
}

- (void)dealloc
{
    [_arrayData release];
    [_arrayOfAtt release];
    [super dealloc];
}

- (void)prepareLayout
{
    [super prepareLayout];
    [self prepare];
}


- (void)prepare
{
    NSInteger num = [self.collectionView numberOfItemsInSection:0];
    for (int i = 0; i < num; i++) {
        NSIndexPath *index = [NSIndexPath indexPathForItem:i inSection:0];
        UICollectionViewLayoutAttributes *att = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:index];
        att.frame = CGRectMake(i * self.collectionView.frame.size.width, 0, self.collectionView.frame.size.width, self.collectionView.frame.size.height);
        _sunOfWidth = _sunOfWidth + self.collectionView.frame.size.width;
        [self.arrayOfAtt addObject:att];
    }
}

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSMutableArray *currentArr = [NSMutableArray array];
    for (UICollectionViewLayoutAttributes *att in self.arrayOfAtt) {
        if (CGRectIntersectsRect(att.frame, rect) || CGRectContainsRect(att.frame, rect)) {
            
            [currentArr addObject:att];
        }
    }
    return currentArr;
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return self.arrayOfAtt[indexPath.item];
}

- (CGSize)collectionViewContentSize
{
    return CGSizeMake(self.collectionView.frame.size.width * 2, 0);
}





@end
